﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace devtm.Aop.Event
{
    
    
    public enum InterceptEnumEventType
    {
        BeforeCall,
        InterceptCall,
        AfterCall,
        Catch
    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class InterceptEventAttribute : Attribute
    {

        public InterceptEventAttribute(InterceptEnumEventType interceptEnum)
        {
            InterceptEnumEventType = interceptEnum;
        }


        public InterceptEnumEventType InterceptEnumEventType { get; private set; }


        internal static bool Valid(System.Reflection.MethodInfo method)
        {

            ParameterInfo[] p = null;
            if (method.ReturnType != typeof(void) || (p = method.GetParameters()).Length !=3)
                return false;

            if (p[0].ParameterType == typeof(object) || p[0].ParameterType == typeof(System.Object) &&
                p[1].ParameterType == typeof(InterceptEventArgs) &&
                p[2].ParameterType == typeof(int) || p[2].ParameterType == typeof(Int32))
                    return true;

            return false;

        }
    }

}
